import FOREACH from "lodash/forEach"
import actionTabs from '@/components/uart/tabs/uTopTabs/action'
const aTTabsStatus = {}
FOREACH(actionTabs,(value,key)=>{
    aTTabsStatus[key] ={active:value.active}
})

const state ={
    actionTabsStatus :aTTabsStatus,
    tabName : null,
    topHeight:0,
    bottomHeight:0,
    uartCfgIndex:-1,
}


const getters = {
    getActionTabsStatus: function(state){
        console.log(state.actionTabsStatus)
        return state.actionTabsStatus
    },
    getUartCfgIndex:function(state){
        return state.uartCfgIndex
    },
    getTabName: function(state){
        return state.tabName
    },
    getTopHeight: function(state){
        return state.topHeight
    },
    getBottomHeight:function(state){
        return state.bottomHeight
    }
}

const mutations = {
    OPENACTIONTABSTATUS(state,name){
        console.log(state.actionTabsStatus)
        state.actionTabsStatus[name].active = true
        state.tabName= name
    },
    CLOSEACTIONTABSTATUS(state,name){
        state.actionTabsStatus[name].active = false
    },
    SETTABNAME(state,name){
        state.tabName = name
    },
    SETSPLITHEIGHT(state,{topHeight,bottomHeight}){
        state.topHeight = topHeight
        state.bottomHeight = bottomHeight
    },
    SETUARTCFGINDEX(state,index){
        state.uartCfgIndex = index
    }
}

const actions = {
    openActionTab({commit},name){
        commit("OPENACTIONTABSTATUS",name)
    },

    closeActionTab({commit},name){
        commit("CLOSEACTIONTABSTATUS",name)
    },
    openUartCfgEditer({dispatch,commit},{name,index}){
        console.log(index)
        commit("SETUARTCFGINDEX",index)
        dispatch("openActionTab",name)
    },
}
console.log(state.actionTabsStatus)

export default {
    state,
    getters,
    mutations,
    actions

}